<template>
  <div class="about" :class="{ 'margin-left': !$store.state.ml }">
    <div class="content-container">
      <!-- 功能 -->
      <div class="search">
        <el-row>
          <el-input
            class="input"
            v-model="input"
            placeholder="商品名称"
          ></el-input>
          <el-button @click="query" class="btn" type="primary">查询</el-button>
          <el-button class="btn" type="primary">添加</el-button>
          <el-button class="btn" type="primary">重置</el-button>
        </el-row>
      </div>

      <!-- 内容 -->
      <el-table :data="tableData" border style="width: 100%">
        <el-table-column fixed prop="id" label="ID" width="180">
        </el-table-column>
        <el-table-column prop="name" label="商品姓名" width="252">
        </el-table-column>
        <el-table-column prop="unit_price" label="售价" width="172">
        </el-table-column>
        <el-table-column prop="unit_price" label="库存" width="172">
        </el-table-column>
        <el-table-column prop="is_new" label="新品" width="172">
          <template v-slot="scope">
            {{ scope.row.is_new ? "是" : "否" }}
          </template>
        </el-table-column>
        <el-table-column prop="is_hot" label="人气" width="172">
          <template v-slot="scope">
            {{ scope.row.is_hot ? "是" : "否" }}
          </template>
        </el-table-column>
        <el-table-column prop="is_new" label="上架" width="172">
          <template v-slot="scope">
            {{ scope.row.is_new ? "是" : "否" }}
          </template>
        </el-table-column>
        <el-table-column prop="sort_order" label="排序" width="172">
        </el-table-column>
        <el-table-column label="操作" width="176">
          <template slot-scope="">
            <el-button type="text" size="small">
              <el-button class="btn" type="primary">编辑</el-button>
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <div class="block">
        <span class="demonstration"></span>
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage4"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="10"
          layout="total, sizes, prev, pager, next, jumper"
          :total="count"
        >
        </el-pagination>
      </div>
    </div>

    <div class="flex bottom">
      <p>
        <b>Copyright © 2016-2019 </b> <span class="qdl">叩丁狼</span>. All
        rights reserved.
      </p>
      <p><b>Version</b> 1.0.0</p>
    </div>
  </div>
</template>

<script>
import { getgoodsapi } from "../request/httpApi";
export default {
  methods: {
    query() {
      getgoodsapi({
        page: "1",
        name: this.input,
        size: "10",
      }).then((okk) => {
        // console.log(okk);
        // console.log(okk.data.count);
        this.tableData = okk.data.data;
        this.count = okk.data.count;
      });
    },
    handleClick(row) {
      console.log(row);
    },
    handleSizeChange(val) {
      this.handleSize = val;
      console.log(`每页 ${val} 条`);
      getgoodsapi({
        page: this.handleCurrent,
        name: this.input,
        size: this.handleSize,
      }).then((okk) => {
        // console.log(okk);
        // console.log(okk.data.count);
        this.tableData = okk.data.data;
        this.count = okk.data.count;
      });
    },
    handleCurrentChange(val1) {
      this.handleCurrent = val1;
      // console.log(`当前页: ${val1}`);
      getgoodsapi({
        page: this.handleCurrent,
        name: this.input,
        size: this.handleSize,
      }).then((okk) => {
        // console.log(okk);
        // console.log(okk.data.count);
        this.tableData = okk.data.data;
        this.count = okk.data.count;
      });
    },
  },
  created() {
    getgoodsapi({
      page: "1",
      // name:  ,
      size: "10",
    }).then((okk) => {
      // console.log(okk);
      // console.log(okk.data.data);
      this.tableData = okk.data.data;
      this.count = okk.data.count;
    });
  },

  data() {
    return {
      handleSize: 10,
      handleCurrent: 1,

      input: "",
      count: 0,
      currentPage4: 1,
      tableData: [],
    };
  },
};
</script>


<style lang = "less" scoped>
.search {
  margin: 10px 0 15px;

  .input {
    width: 200px;
    margin-right: 10px;
    /* height: 32px;
    line-height: 32px; */
  }
}
</style>
